//
//  AudioFileIOManager_MACOSX.h
//  LowPassFilter_Standalone
//
//  Created by kadlubek47 on 02.08.2013.
//  Copyright (c) 2013 kadlubek47. All rights reserved.
//

#ifndef LowPassFilter_Standalone_AudioFileIOManager_MACOSX_h
#define LowPassFilter_Standalone_AudioFileIOManager_MACOSX_h

#include "IAudioFileIOManager.h"

#include <AudioToolbox/ExtendedAudioFile.h>

/*
 @TODO:
 - many channels
 - cleaning
 - too long names
 */


class AudioFileIOManager_MACOSX: public IAudioFileIOManager {
public:
    AudioFileIOManager_MACOSX();
    ~AudioFileIOManager_MACOSX();
    
    void read(const char* pathToFile, int wantedBytePerSample, long long int* length /*out*/, void*** channels /*out*/, int* numOfChannels /*out*/, unsigned int* samplingRate /*out*/);
    void write(void** channels, const char* pathToNewFile);
    
    static void printDescription(AudioStreamBasicDescription descr);
    
private:
    int numOfChannels_;
    
    SInt64 inFileLength_;
    ExtAudioFileRef inFileReference_;
    AudioBufferList inFileBuffer_;
    AudioStreamBasicDescription inFileDescription_;
    
    UInt32 numberFramesRead_;
    AudioStreamBasicDescription bufferDescription_;
    
    AudioBufferList outFileBuffer_;
    AudioStreamBasicDescription outFileDescription_;
    
    //read
    void getFileDescription();
    void setConvertingBufferParameters(int bytePerSample);
    void readFileIntoBuffer();
    void getAudio(long long int* length /*out*/, void*** channels /*out*/, int* numberOfChannels /*out*/);
    
    //write
    void setAudio(void** channel);
    void setConvertingOutFileParameters();
  
};


#endif
